<template>
  <!-- Form -->
   <el-select v-model="value" class="m-2" placeholder="请选择排序方式"> 

     <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value"
    />
  </el-select>
  <el-input v-model="input" placeholder="搜索框" /><el-button type="primary" :icon="Search">Search</el-button> <el-button type="primary" @click="open11">新增</el-button> 
  <el-dialog v-model="dialogFormVisible" title="新增">
    <el-form :model="form">
      <el-form-item label="问题分类名称" :label-width="formLabelWidth">
        <el-input v-model="form.name" autocomplete="off" />
      </el-form-item>
      <el-form-item label="父级分类" :label-width="formLabelWidth">
        <el-select v-model="form.region" placeholder="请选择一种类别">
          <el-option label="Zone No.1" value="shanghai" />
          <el-option label="Zone No.2" value="beijing" />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="open1">取消</el-button>
        <el-button type="primary" @click="handleAdd"
          >确认</el-button
        >
      </span>
    </template>
  </el-dialog>
</template>

<script>
import { reactive, ref } from 'vue'
import axios from "axios"
export default{
    props: {
        title: String
    },
    setup(props){
        const dialogFormVisible = ref(false)
        const formLabelWidth = '140px'
        const input = ref('')
        const form = reactive({
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: '',
        })
        const value = ref('')
        const options = [
          {
            value: 'Option1',
            label: '热度',
          },
          {
            value: 'Option2',
            label: '提问时间',
          },
          {
            value: 'Option3',
            label: '问题类型',
          },
        ]
        const open11 = ()=> {
            form.name=""
            form.region=""
            dialogFormVisible.value = true
        }
        // 添加
        const handleAdd = () =>  {
            
            axios.post(`/Api/category/add`,form).then(res=>{
            console.log(res)
            })
             dialogFormVisible.value = false
             open2()
        }
        // 取消
        const cencel = () => {

        }
        // 成功
        const open2 = () => {
            ElMessage({
                message: '添加成功!',
                type: 'success',
            })
        }
        const open4 = () => {
            ElMessage.error('修改不成功!')
        }
        const open1 = () => {
            dialogFormVisible.value = false
            ElMessage({
            showClose: true,
            message: '操作取消.',
        })
}
        return{dialogFormVisible,formLabelWidth,form,handleAdd,open2,open11,open1,options}
    }
    
}


// function handleAdd() {
//     axios.post("/sss",form).then((res)=>{
//         console.log(res)
//             })
//         }
// }

   
</script>
<style scoped>
.el-button--text {
  margin-right: 15px;
}
.el-select {
  width: 300px;
}
.el-input {
  width: 300px;
}
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
